import { ref } from 'vue'
import ycDialog from '@/base-ui/dialog'

type CallBackFn = (item?: any) => void
export function usePageDialog(newCallBack?: CallBackFn, editCallBack?: CallBackFn): any {
  const dialogRef = ref<InstanceType<typeof ycDialog>>()
  const defaultInfo = ref({})
  const dialogTitle = ref('')

  function handleNewData() {
    dialogRef.value?.openDialog()
    dialogTitle.value = '新建'
    newCallBack && newCallBack()
  }
  function editClick(row: any) {
    editCallBack && editCallBack(row)
    dialogTitle.value = '修改'

    dialogRef.value?.openDialog()

    defaultInfo.value = { ...row }
  }
  return {
    handleNewData,
    editClick,
    defaultInfo,
    dialogRef,
    dialogTitle
  }
}
